from rest_framework import serializers
from product.models import Product


class ProductSerializer(serializers.ModelSerializer):
    """
    产品序列化器
    用于处理产品数据的序列化和反序列化
    """
    class Meta:
        model = Product
        fields = [
            'product_id', 'product_type', 'sku', 'name', 'spc', 'description',
            'category_id', 'unit_pr', 'unit_wh', 'unit_use', 'unit_rate',
            'status', 'sku_supplier', 'barcode', 'inventory_method', 'costing_method',
            'is_batch_tracked', 'is_serial_tracked', 'shelf_life_days',
            'safety_stock', 'reorder_point', 'max_stock', 'default_warehouse_id',
            'default_location', 'preferred_supplier_id', 'purchaser_id', 'lead_time',
            'moq', 'tax_code', 'version', 'last_purchase_price', 'list_price',
            'standard_cost', 'current_cost', 'income_account_id', 'cogs_account_id',
            'asset_account_id', 'create_time', 'update_time', 'creator', 'modifier'
        ]
        read_only_fields = ['product_id', 'create_time', 'update_time', 'creator', 'modifier']